package com.fenqiyong.www.action;

import android.content.Context;

import com.orhanobut.logger.Logger;
import com.tougc.bean.beans.BannerBean;
import com.tougc.bean.beans.CardIndexBean;
import com.tougc.bean.beans.ProductIndexBean;

import javax.inject.Inject;

import io.reactivex.Observable;
import ren.nearby.http.request.BaseObserver;
import ren.nearby.http.request.HttpApi;
import ren.nearby.http.request.RxResultHelper;
import ren.nearby.http.request.SchedulersCompat;
import ren.nearby.http.utils.util.RxDisposble;

/**
 * Created by Administrator on 2018/5/18 0018.
 */

public class FragmentIndexPresent implements FragmentIndexContract.Action {
    FragmentIndexContract.View mView;  // 需要抽象出来
    @Inject
    HttpApi mApi;
    @Inject
    Context context;

    @Inject
    FragmentIndexPresent() {
    }

    @Override
    public void takeView(FragmentIndexContract.View view) {
        mView = view;
    }

    @Override
    public void dropView() {
        mView = null;
        RxDisposble.getInstance().unSubscribe();
    }

    @Override
    public void concatIndex(int page, int size) {
        Observable ob23 = mApi.bannerIndex();
        Observable ob24 = mApi.cardIndex();
        Observable ob25 = mApi.productIndex(0, page, size);
        BaseObserver observer1 = new BaseObserver<BannerBean>(mView.getActivity()) {




            @Override
            public void onNext(BannerBean ob) {
                Logger.e("BannerBean = ");
                mView.banner(ob.getList());
            }
        };
        BaseObserver observer2 = new BaseObserver<CardIndexBean>(mView.getActivity()) {



            @Override
            public void onNext(CardIndexBean ob) {
                Logger.e("CardIndexBean  = ");
                mView.card(ob.getList());
            }
        };
        BaseObserver observer3 = new BaseObserver<ProductIndexBean>(mView.getActivity()) {



            @Override
            public void onNext(ProductIndexBean ob) {
                Logger.e("ProductIndexBean  = ");
                mView.product(ob.getList());
            }
        };
        ob23.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
                .compose(RxResultHelper.handleResult14K()).subscribe(observer1);
        ob24.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
                .compose(RxResultHelper.handleResult14K()).subscribe(observer2);
        ob25.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
                .compose(RxResultHelper.handleResult14K()).subscribe(observer3);

        Observable.concat(ob23, ob24, ob25);
    }
    @Override
    public void concatIndex2(int page, int size) {
        Observable ob25 = mApi.productIndex(0, page, size);
        BaseObserver observer3 = new BaseObserver<ProductIndexBean>(mView.getActivity()) {
            @Override
            public void onNext(ProductIndexBean ob) {
                Logger.e("ProductIndexBean  = ");
                mView.product(ob.getList());
            }
        };
        ob25.compose(SchedulersCompat.IO_TRANSFORMER)//处理线程
                .compose(RxResultHelper.handleResult14K())
                .subscribe(observer3);
    }
}


